<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<input type="text" placeholder="请输入1-100之间的整数"/>
<input type="button" value="猜一猜" onclick="f()"/>
<h3>
  结果：<span></span>
</h3>
<span id = "s2"></span>
</body>
<script>
  let x = parseInt(Math.random()*100+1);

  let i1 = document.querySelector("input");
  let s = document.querySelector("span");
  let s2 = document.querySelector("#s2");
  let n = 0;
  function f(){
    let i1Num = i1.value;
    if(isNaN(i1Num)){
      s.innerText = "输入错误";
      return;
    }
    i1Num = parseFloat(i1Num);
    n++;
    s2.innerText = s2.innerText+i1Num+",";
    if(i1Num>x){
      s.innerText = "猜大了！";
    }else if(i1Num<x){
      s.innerText = "猜小了";
    }else{
      s.innerText = "第"+n+"次猜对了";
      n = 0;
    }

  }

</script>
</html>